package com.gjr.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gjr.eduservice.client.VodClient;
import com.gjr.eduservice.entity.EduVideo;
import com.gjr.eduservice.mapper.EduVideoMapper;
import com.gjr.eduservice.service.EduVideoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 课程视频 服务实现类
 * </p>
 *
 * @author gjr
 * @since 2022-09-01
 */
@Service
public class EduVideoServiceImpl extends ServiceImpl<EduVideoMapper, EduVideo> implements EduVideoService {

    @Autowired
    private VodClient vodClient;

    /**
     * 根据课程id删除小节
     *
     * @param courseId 课程id
     */
    @Override
    public void removeVideoByCourseId(String courseId) {
        List<String> videoIdList = baseMapper.getVideoIdList(courseId);

        if (!videoIdList.isEmpty() && videoIdList.size() > 0) {
            // 批量删除阿里云端视频
            vodClient.deleteBatch(videoIdList);
        }

        this.remove(new LambdaQueryWrapper<EduVideo>().eq(EduVideo::getCourseId, courseId));
    }
}
